﻿//Paul Create
function Class() { var aDefine = arguments[arguments.length - 1]; if (!aDefine) { return } var aBase = arguments.length > 1 ? arguments[0] : object; function prototype_() { } prototype_.prototype = aBase.prototype; var aPrototype = new prototype_(); for (var member in aDefine) { if (member != "Create") { aPrototype[member] = aDefine[member] } } if (aDefine.Create) { var aType = aDefine.Create } else { aType = function () { this.base.apply(this, arguments) } } aType.prototype = aPrototype; aType.Base = aBase; aType.prototype.Type = aType; return aType } function object() { } object.prototype.isA = function (aType) { var self = this.Type; while (self) { if (self == aType) { return true } self = self.Base } return false }; object.prototype.base = function () { var Caller = object.prototype.base.caller; Caller && Caller.Base && Caller.Base.apply(this, arguments) };


/*
*功能：扩展jquery
*作者：谢跃（Paul）
*日期：2012-11-22 create
*/
(function ($) {
    $.fn.extend({
        //文本内容去掉首尾空白
        ValTrim: function () {
            return $.trim(this.val());
        }
    })
})(jQuery);

String.prototype.Bind = function () {
    if (this.length < 1)
        return 'N/A';
    return this;
};

String.prototype.Format = function () {
    //    var formatted = this;
    //    for (var i = 0; i < arguments.length; i++) {
    //        var regexp = new RegExp('\\{' + i + '\\}', 'gi');
    //        formatted = formatted.replace(regexp, arguments[i]);
    //    }
    //    return formatted;

    var args = arguments;
    return this.replace(/\{(\d+)\}/g, function (m, i, o, n) {
        return args[i];
    });

};

//String.prototype.Trim = function () {

//    return $.trim(this);

//};


if (typeof String.prototype.Trim == 'undefined') {
    String.prototype.Trim = function () {
        return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
    }
}

(function ($) {
    $.fn.placeholder = function (options) {
        var defaults = {
            pColor: "#BEBEBE",
            pActive: "#999",
            pFont: "14px",
            activeBorder: "#080",
            posL: 8,
            zIndex: "99"
        },
        opts = $.extend(defaults, options);
        $(".test").remove();
        return this.each(function () {
            if ("placeholder" in document.createElement("input")) return;
            $(this).parent().css("position", "relative");
            //            var isIE = $.browser.msie,
            //            version = $.browser.version;
            if (!$(this).is(":hidden")) {//不支持placeholder的浏览器
                var $this = $(this),
                    msg = $this.attr("placeholder"),
                    iH = $this.outerHeight(),
                    iW = $this.outerWidth(),
                    iX = $this.position().left,
                    iY = $this.position().top,
                    oInput = $("<label>", {
                        "class": "test",
                        "text": msg,
                        "css": {
                            "position": "absolute",
                            "left": iX + "px",
                            "top": iY + "px",
                            "width": iW - opts.posL + "px",
                            "padding-left": opts.posL + "px",
                            "height": iH + "px",
                            "line-height": iH + "px",
                            "color": opts.pColor,
                            "font-size": opts.pFont,
                            "z-index": opts.zIndex,
                            "cursor": "text"
                        }
                    }).insertBefore($this);
                //初始状态就有内容
                var value = $this.val();
                if (value.length > 0) {
                    oInput.hide();
                };
                $this.on("focus", function () {
                    oInput.hide();
                    oInput.css("color", opts.pActive);
                }).on("blur", function () {
                    var value = $(this).val();
                    if (value.length == 0) {
                        oInput.css("color", opts.pColor).show();
                    }
                });
                oInput.on("click", function () {
                    $this.trigger("focus");
                    $(this).css("color", opts.pActive);
                });
                $this.filter(":focus").trigger("focus");
            }
        });
    };
})(jQuery);

/**
 * 分页数据通用实体
 */
var PageEntity = Class(object, {
    Create: function () {
        this.PageSize = 10;
        this.PageIndex = 1;
        this.PageCount = 1;
        this.RowCount = 1;
        this.PageData = [];
        this.OrderColumnName = "";
        this.IsOrderByDesc = true;

    }
});

var BaseQueryCondition = Class(object, {

    Create: function () {
        this.PageSize = 10;
        this.PageIndex = 1;
        this.OrderColumnName = "";
        this.IsOrderByDesc = true;
    }
});
var Createorder = Class(object, {
    Create: function () {
        this.Commodityid = "";
        this.Createtime = "";
        this.Phonenum = "";
        this.Msgconter = "";
        this.Remark = "";
    }
});

var FiancialQueryResult = Class(object, {
    Create: function () {
        this.AlipayTotal = 0;
        this.AlipayGold = 0;
        this.AlipayMoney = 0;
        this.UnionPayTotal = 0;
        this.UnionPayGold = 0;
        this.UnionPayMoney = 0;
        this.SmallamountTotal = 0;
        this.SmallamountGold = 0;
        this.SmallamountMoney = 0;
        this.BillBuy = 0;
        this.GoldBuy = 0;

    }
});

var GoldUseInfo = Class(object, {
    Create: function () {
        this.GoldUse = 0.0;
        this.GoldPay = 0.0;
        this.Alipaypay = 0.0;
        this.IntegralPay = 0.0;
        this.UnionPayPay = 0.0;
        this.SmallamountPay = 0.0;
        this.MobilePay = 0.0;
        this.ActivityPay = 0.0;
        this.HandAdd = 0.0;
        this.Otherpay = 0.0;

    }
});


//#region 全局公用信息
var Gloabl = {};
Gloabl.LoginInfo = {
    name: "张三",
    id: "23223",
    token: "TGDSDFE",
    rightCode: 234
};

//#endregion

//#region Base64转码
var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var base64DecodeChars = new Array(
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
    52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
    -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
    15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
    -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
    41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);

function base64encode(str) {
    var out, i, len;
    var c1, c2, c3;

    len = str.length;
    i = 0;
    out = "";
    while (i < len) {
        c1 = str.charCodeAt(i++) & 0xff;
        if (i == len) {
            out += base64EncodeChars.charAt(c1 >> 2);
            out += base64EncodeChars.charAt((c1 & 0x3) << 4);
            out += "==";
            break;
        }
        c2 = str.charCodeAt(i++);
        if (i == len) {
            out += base64EncodeChars.charAt(c1 >> 2);
            out += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
            out += base64EncodeChars.charAt((c2 & 0xF) << 2);
            out += "=";
            break;
        }
        c3 = str.charCodeAt(i++);
        out += base64EncodeChars.charAt(c1 >> 2);
        out += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
        out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6));
        out += base64EncodeChars.charAt(c3 & 0x3F);
    }
    return out;
}

function base64decode(str) {
    var c1, c2, c3, c4;
    var i, len, out;

    len = str.length;
    i = 0;
    out = "";
    while (i < len) {
        /* c1 */
        do {
            c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
        } while (i < len && c1 == -1);
        if (c1 == -1)
            break;

        /* c2 */
        do {
            c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
        } while (i < len && c2 == -1);
        if (c2 == -1)
            break;

        out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));

        /* c3 */
        do {
            c3 = str.charCodeAt(i++) & 0xff;
            if (c3 == 61)
                return out;
            c3 = base64DecodeChars[c3];
        } while (i < len && c3 == -1);
        if (c3 == -1)
            break;

        out += String.fromCharCode(((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2));

        /* c4 */
        do {
            c4 = str.charCodeAt(i++) & 0xff;
            if (c4 == 61)
                return out;
            c4 = base64DecodeChars[c4];
        } while (i < len && c4 == -1);
        if (c4 == -1)
            break;
        out += String.fromCharCode(((c3 & 0x03) << 6) | c4);
    }
    return out;
}

function utf16to8(str) {
    var out, i, len, c;

    out = "";
    len = str.length;
    for (i = 0; i < len; i++) {
        c = str.charCodeAt(i);
        if ((c >= 0x0001) && (c <= 0x007F)) {
            out += str.charAt(i);
        } else if (c > 0x07FF) {
            out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
            out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
            out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
        } else {
            out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
            out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
        }
    }
    return out;
}

function utf8to16(str) {
    var out, i, len, c;
    var char2, char3;

    out = "";
    len = str.length;
    i = 0;
    while (i < len) {
        c = str.charCodeAt(i++);
        switch (c >> 4) {
            case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
                // 0xxxxxxx
                out += str.charAt(i - 1);
                break;
            case 12: case 13:
                // 110x xxxx   10xx xxxx
                char2 = str.charCodeAt(i++);
                out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
                break;
            case 14:
                // 1110 xxxx  10xx xxxx  10xx xxxx
                char2 = str.charCodeAt(i++);
                char3 = str.charCodeAt(i++);
                out += String.fromCharCode(((c & 0x0F) << 12) |
                               ((char2 & 0x3F) << 6) |
                               ((char3 & 0x3F) << 0));
                break;
        }
    }

    return out;
}


function doit() {
    var f = document.f;
    f.output.value = base64encode(utf16to8(f.source.value));
    f.decode.value = utf8to16(base64decode(f.output.value));
}



//#endregion

//#region 其他函数方法



/*自定义alert界面，系统默认alert太难看了*/
function ShowAlert(info, fun) {
    //if (fun)
    //    layer.alert(info, fun);
    //else
    //    layer.alert(info);


    layer.open({
        title: [
            '享动健身',
            'background-color:#e9b462; color:#fff;'
        ]
        , anim: 'up'
        , content: info
,shadeClose: false
        , btn: ['确认']
        , yes: function (index, layero) {
            //按钮【按钮一】的回调
            if (fun)
                fun();
            layer.closeAll('dialog'); //关闭信息框

        }
    });


    //layer.open({
    //    title:' '
    //    ,content: info
    //    , btn: ['确认']
    //    , yes: function (index, layero) {
    //        //按钮【按钮一】的回调
    //        if (fun)
    //            fun();
    //        layer.closeAll('dialog'); //关闭信息框
                
    //    }
        
    //});


}

function ShowTips(txt, target) {

    layer.tips(txt, $("#btnAndWork"), {
        tips: [1, '#3595CC'],
        time: 4000,
        close: function () {
            alert('');
        }
    });
}


//弹出询框 电脑板laer
//function ShowComfirm(askTxt, yesBtnTxt, noBtnTxt, yesFuc, noFuc) {

//    layer.confirm(askTxt, {
//        btn: [yesBtnTxt, noBtnTxt] //按钮
//    }, function () {
//        yesFuc();
//    }, function () {
//        if (noFuc)
//            noFuc();
//    });
//}

function ShowComfirm(askTxt, yesBtnTxt, noBtnTxt, yesFuc, noFuc) {
    layer.open({
        title: [
            '享动健身',
            'background-color:#e9b462; font-size:38px; height:80px; line-height:80px; color:#fff;'
        ]
        ,content: askTxt
        , btn: [yesBtnTxt, noBtnTxt]
        , yes: function (index) {
            yesFuc();
            layer.close(index);
        }
    });
}

//function ShowAlert(info) {
//    HidenDealCover();
//    Boxy.alert(info, null, { title: "操作失败", closeable: true, closeText: 'Close' });
//    // Boxy.load('fdsafdsafdsaf', { title: "支付记录", unloadOnHide: true, closeable: true });

//}

//function ShowAlert(info, doSth) {
//    HidenDealCover();
//    Boxy.alert(info, doSth, { title: "操作失败", closeable: true, closeText: 'Close' });

//}

//function ShowAsk(info, yes, no, yesFuc, noFuc) {
//    HidenDealCover();
//    var dialog = Boxy.ask(info, [yes, no], function (item) {

//        if (item == yes)
//            yesFuc();
//        else if (item == no) {
//            noFuc();
//            //  dialog.close();
//            // dialog.hide();
//        }
//    });
//}

//显示遮罩层
function ShowDealCover() {
    $.blockUI({ message: GlobalTextInfo.Info_loading });
}

///显示自定义文本的遮罩层
function ShowDealCover(parameters) {
    $.blockUI({ message: parameters, width: '60%' });
}

//隐藏遮罩层
function HidenDealCover() {
    try {
        $.unblockUI();
    } catch (e) {
    }

}

//获取post请求 需要发送给代理的参数
function GetPostData(sitenamne, invokeMethod, dataForMethod) {
    //指定服务参数
    var clientParams = {
        site: sitenamne, //站点名称
        urlName: invokeMethod, //对应服务Url名称
        postUserInfo: true //是否需要向Service传送User信息，true:传送
    };

    //将jsondata 和clientParams 构建成一个对象 作为js代用代理的参数
    var ClientRequestObject = {
        clientParams: clientParams,
        data: JSON.stringify(dataForMethod)
    };

    return ClientRequestObject;
}


//指定Id上遮罩
function showMaskWithId(maskId) {
    $("#" + maskId).block({
        message: '<img src="/images/preloader.gif" />',
        css: {
            border: 'none',
            padding: '15px',
            '-webkit-border-radius': '10px',
            '-moz-border-radius': '10px'
        },
        overlayCSS: { backgroundColor: '#fff' }
    });
}

//function getUrlParam(name) {
//    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
//    var r = window.location.search.substr(1).match(reg); //匹配目标参数
//    if (r != null) return unescape(r[2]); return null; //返回参数值
//}

function setCookie(name, value) {
    var Days = 30;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + encodeURIComponent(value) + ";expires=" + exp.toGMTString() + "; path=/";;
}


function setCookieNoExpire(name, value) {

    // exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value);
}

//读取cookies 
function getCookie(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");

    if (arr = document.cookie.match(reg))

        return decodeURIComponent(arr[2]);
    else
        return null;
}

//删除cookies 
function delCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getCookie(name);
    if (cval != null)
        document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}


//移除指定Id上遮罩
function removeMaskWithId(maskId, onUnblock) {
    $("#" + maskId).unblock({ onUnblock: onUnblock });
}

var checkMaskId = function (MaskAreaId) {
    return typeof (MaskAreaId) != "undefined" && MaskAreaId;
};

//#endregion
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = decodeURI(window.location.search).substr(1).match(reg); //匹配目标参数
    if (r != null) return unescape(r[2]); return null; //返回参数值
}

function GetOpenId(oid) {
    var _oid = "fid";
    if (typeof (oid) != "undefined")
        _oid = oid;
    var cookieValue = getCookie(_oid);
    if (cookieValue == null ) {
        document.location.href = "/Home/GetOpenidByAuth?f=" + document.location.href;
    }
    else
        return cookieValue;
};

function GetUserPhone(phone) {
    var _phone = "AuthPhone";
    if (typeof (phone) != "undefined")
        _phone = phone;
    var cookieValue = getCookie(_phone);
    if (cookieValue == null) {
        document.location.href = "/Home/GetPhoneByAuth?back=" + document.location.href;
    }
    else
        return cookieValue;
};


